package org.programmers.anonymous.fightrobots.model;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;

/**
 * Implements the message object
 * @author David Rodriguez, Francisco Villalba
 *
 */

@JsonTypeInfo( use = Id.NAME )
@JsonSubTypes(
    {
        @Type( name = "Action", value = ActionMessage.class ),
        @Type( name = "Status", value = StatusMessage.class ),
        @Type( name = "Error", value = ErrorMessage.class ),
        @Type( name = "Query", value = QueryMessage.class )
    }
)
public abstract class Message implements IMessage {

	/**
	 * private attributes
	 */
	protected IURLId mySender, myReceiver;

    public Message(){
		this.mySender = null;
		this.myReceiver = null;
    }

	/**
	 * Default  constructor
	 */
	public Message(IURLId sender, IURLId receiver) {
		this.mySender = sender;
		this.myReceiver = receiver;


	}

	@Override
	/*
	 * (non-Javadoc)
	 * @see org.programmers.anonymous.fightrobots.model.IMessage#getOrigin()
	 */
	public IURLId getMySender() {
		return this.mySender;
	}

	@Override
	/*
	 * (non-Javadoc)
	 * @see org.programmers.anonymous.fightrobots.model.IMessage#getRemote()
	 */
	public IURLId getMyReceiver() {
		return this.myReceiver;
	}
	

	public void setMySender(IURLId mySender) {
		this.mySender = mySender;
	}


	public void setMyReceiver(IURLId myReceiver) {
		this.myReceiver = myReceiver;
	}


	@Override
	public String toString()
	{
		StringBuffer strBuff = new StringBuffer();
		
		strBuff.append(getClass().getSimpleName());
		strBuff.append(":{");
		strBuff.append("{sender:");
		strBuff.append(this.mySender);
		strBuff.append(",receiver:");
		strBuff.append(this.myReceiver);
		strBuff.append("}");
		
		return strBuff.toString();
	}



}
